﻿using UnityEngine;
using System.Collections;

public class AnimationController : MonoBehaviour {

    public Animator Glass;
    private AnimationUtil util;
    private bool isJumping;

    void Awake()
    {
        util = gameObject.AddComponent("AnimationUtil") as AnimationUtil;
    }
	void Update ()
    {

        if (Input.GetAxisRaw("Vertical") > 0 && GetComponent<Movement>().grounded)
        {
            GetComponent<Animator>().SetBool("WalkingLeft", false);
            GetComponent<Animator>().SetBool("WalkingRight", false);
            GetComponent<Animator>().SetBool("isJumping", true);
            StartCoroutine(util.DisableAnimationAfterTime("isJumping", 0.2f));
            StartCoroutine(util.EnableAnimationAfterTime("JumpFalling", 0.2f));
            
            Glass.SetBool("WalkingLeft", false);
            Glass.SetBool("WalkingRight", false);
            Glass.SetBool("isJumping", true);
            StartCoroutine(util.DisableAnimationAfterTime("isJumping", 0.2f, Glass));
            StartCoroutine(util.EnableAnimationAfterTime("JumpFalling", 0.2f, Glass));

        }

        if (Input.GetAxisRaw("Horizontal") > 0)
        {
            GetComponent<Animator>().SetBool("WalkingRight", true);
            Glass.SetBool("WalkingRight", true);
        }
        if (Input.GetAxisRaw("Horizontal") < 0)
        {
            GetComponent<Animator>().SetBool("WalkingLeft", true);
            Glass.SetBool("WalkingLeft", true);
        }

        if (Input.GetAxisRaw("Horizontal") == 0)
        {
            GetComponent<Animator>().SetBool("WalkingRight", false);
            Glass.SetBool("WalkingRight", false);
            GetComponent<Animator>().SetBool("WalkingLeft", false);
            Glass.SetBool("WalkingLeft", false);
        }



        if (Input.GetKeyDown(KeyCode.K))
        {
            GetComponent<Animator>().SetBool("Kicking", true);
            StartCoroutine(util.DisableAnimationAfterTime("Kicking", .5f));
            Glass.SetBool("Kicking", true);
            StartCoroutine(util.DisableAnimationAfterTime("Kicking", .5f, Glass));
        }
	}

}
